package com.zzh.myapplication.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import net.icarplus.car.R;
import net.icarplus.car.bean.MicroEnergyBean;

import java.util.List;

/**
 * Created by Administrator on 2016/3/25.
 */
public class MicroEnergyAdapager extends BaseAdapter {
    private Context context;

    public MicroEnergyAdapager(Context context) {
        this.context = context;
    }
    public List<MicroEnergyBean> getList_micro() {
        return list_micro;
    }
    public void setList_micro(List<MicroEnergyBean> list_micro) {
        this.list_micro = list_micro;
        /*list_micro.clear();
        list_micro.addAll(list_micro);*/
    }

    private List<MicroEnergyBean> list_micro;

    @Override
    public int getCount() {
        return list_micro == null ? 0 : list_micro.size();
    }

    @Override
    public Object getItem(int position) {
        return list_micro.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodle hodle;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.itme_micro_energy, null);
            hodle = new ViewHodle(convertView);
            convertView.setTag(hodle);
        } else {
            hodle = (ViewHodle) convertView.getTag();
        }
        MicroEnergyBean bean = list_micro.get(position);
        hodle.iamge.setImageURI(Uri.parse(bean.getImage()));
        hodle.tv_name.setText(bean.getTv_name());
        hodle.tv_time.setText(bean.getTv_time() + "");
        hodle.tv_phone.setText(bean.getTv_phone() + "");
        hodle.tv_time_moth.setText(bean.getTv_time_moth() + "");
        return convertView;
    }

    class ViewHodle {
        SimpleDraweeView iamge;
        TextView tv_time, tv_time_moth, tv_name, tv_phone;

        public ViewHodle(View convertView) {
            iamge = (SimpleDraweeView) convertView.findViewById(R.id.image);
            tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            tv_time_moth = (TextView) convertView.findViewById(R.id.tv_time_moth);
            tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);

        }
    }
}
